<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>QUnit for hex represented ASN.1 library 'asn1hex.js'</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />


<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/rsa.js"></script>
<script src="../ext/rsa2.js"></script>
<script src="../ext/base64.js"></script>
<script src="../src/base64x-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/asn1x509-1.0.js"></script>

<script type="text/javascript">
$(document).ready(function(){

var sZ4_CERPEM = (function() {/*
-----BEGIN CERTIFICATE-----
MIIC/zCCAeegAwIBAgIBATANBgkqhkiG9w0BAQUFADAaMQswCQYDVQQGEwJVUzEL
MAkGA1UECgwCWjQwHhcNMTMwODI4MTgyODM0WhcNMjMwODI4MTgyODM0WjAaMQsw
CQYDVQQGEwJVUzELMAkGA1UECgwCWjQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
ggEKAoIBAQDfdOqotHd55SYO0dLz2oXengw/tZ+q3ZmOPeVmMuOMIYO/Cv1wk2U0
OK4pug4OBSJPhl09Zs6IwB8NwPOU7EDTgMOcQUYB/6QNCI1J7Zm2oLtuchzz4pIb
+o4ZAhVprLhRyvqi8OTKQ7kfGfs5Tuwmn1M/0fQkfzMxADpjOKNgf0uy6lN6utjd
TrPKKFUQNdc6/Ty8EeTnQEwUlsT2LAXCfEKxTn5RlRljDztS7Sfgs8VL0FPy1Qi8
B+dFcgRYKFrcpsVaZ1lBmXKsXDRu5QR/Rg3f9DRq4GR1sNH8RLY9uApMl2SNz+sR
4zRPG85R/se5Q06Gu0BUQ3UPm67ETVZLAgMBAAGjUDBOMB0GA1UdDgQWBBQHZPTE
yQVu/0I/3QWhlTyW7WoTzTAfBgNVHSMEGDAWgBQHZPTEyQVu/0I/3QWhlTyW7WoT
zTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4IBAQDHxqJ9y8alTH7agVMW
Zfic/RbrdvHwyq+IOrgDToqyo0w+IZ6BCn9vjv5iuhqu4ForOWDAFpQKZW0DLBJE
Qy/7/0+9pk2DPhK1XzdOovlSrkRt+GcEpGnUXnzACXDBbO0+Wrk+hcjEkQRRK1bW
2rknARIEJG9GS+pShP9Bq/0BmNsMepdNcBa0z3a5B0fzFyCQoUlX6RTqxRw1h1Qt
5F00pfsp7SjXVIvYcewHaNASbto1n5hrSz1VY9hLba11ivL1N4WoWbmzAL6BWabs
C2D/MenST2/X6hTKyGXpg3Eg2h3iLvUtwcNny0hRKstc73Jl9xR3qXfXKJH0ThTl
q0gq
-----END CERTIFICATE-----
*/}).toString().match(/\/\*([^]*)\*\//)[1];

test("ASN1HEX.getLblen", function() {
  equal(ASN1HEX.getLblen('020100', 0), 1, "checking L.len of 020100 is 1.");
  equal(ASN1HEX.getLblen('020300', 0), 1, "checking L.len of 020300 is 1.");
  equal(ASN1HEX.getLblen('02818003...', 0), 2, "checking L.len of 02818003... is 2.");
  equal(ASN1HEX.getLblen('0282025b03...', 0), 3, "checking L.len of 0282025b03... is 3.");
  equal(ASN1HEX.getLblen('0280020100...', 0), -1,
         "checking L.len of 0280020100... is -1(indefinite length).");
  equal(ASN1HEX.getLblen('ffff0201ab', 4), 1, "check L.len at 4 of ffff0201ab.");
});

test("ASN1HEX.getL", function() {
  equal(ASN1HEX.getL('020100', 0), '01', "check L octets of 020100.");
  equal(ASN1HEX.getL('020300', 0), '03', "check L octets of 020300.");
  equal(ASN1HEX.getL('02818003...', 0), '8180', "check L octets of 02818003.");
  equal(ASN1HEX.getL('0282025b03...', 0), '82025b', "check L octets of 0282025b03.");
  equal(ASN1HEX.getL('0280020100...', 0), '',
         "check L of 0280020100.(indefinite length).");
  equal(ASN1HEX.getL('ffff0201ab', 4), '01', "check L octets at 4 of ffff0201ab.");
});

test("ASN1HEX.getVblen", function() {
  expect(6);
  equal(ASN1HEX.getVblen('020100', 0), 1, "check L of 020100.");
  equal(ASN1HEX.getVblen('020300', 0), 3, "check L of 020300.");
  equal(ASN1HEX.getVblen('02818003...', 0), 128, "check L of 02818003.");
  equal(ASN1HEX.getVblen('0282025b03...', 0), 603, "check L of 0282025b03.");
  equal(ASN1HEX.getVblen('0280020100...', 0), -1,
         "check of 0280020100.(indefinite length).");
  equal(ASN1HEX.getVblen('ffff0201ab', 4), 1, "check L at 4 of ffff0201ab.");
});

test("ASN1HEX.getVidx", function() {
  expect(6);
  equal(ASN1HEX.getVidx('020100', 0), 4, "check V pos of 020100.");
  equal(ASN1HEX.getVidx('020300', 0), 4, "check V pos of 020300.");
  equal(ASN1HEX.getVidx('02818003...', 0), 6, "check V pos of 02818003.");
  equal(ASN1HEX.getVidx('0282025b03...', 0), 8, "check V pos of 0282025b03.");
  equal(ASN1HEX.getVidx('0280020100...', 0), -1,
         "check V pos of 0280020100.(indefinite length).");
  equal(ASN1HEX.getVidx('ffff0201ab', 4), 8, "check V pos at 4 of ffff0201ab.");
});

test("ASN1HEX.getV", function() {
  equal(ASN1HEX.getV('0201ab', 0), 'ab', "check V of 0201ab.");
  equal(ASN1HEX.getV('0203012345', 0), '012345', "check V of 0203012345.");
  equal(ASN1HEX.getV('ffff0201ab', 4), 'ab', "check V at 4 of ffff0201ab.");
  equal(ASN1HEX.getV('024100EE6D7FE55461600FFC58B9C873E7A61CED51D7FB9F015243527B04B3C0945B72E7AA9275D15B08FDED25EAA6761F2AA66AEFC767105D74496B2BFCD30A8BEED7', 0), '00EE6D7FE55461600FFC58B9C873E7A61CED51D7FB9F015243527B04B3C0945B72E7AA9275D15B08FDED25EAA6761F2AA66AEFC767105D74496B2BFCD30A8BEED7', "check V of 024100EE...");
  equal(ASN1HEX.getV('FFFF024100EE6D7FE55461600FFC58B9C873E7A61CED51D7FB9F015243527B04B3C0945B72E7AA9275D15B08FDED25EAA6761F2AA66AEFC767105D74496B2BFCD30A8BEED7FFFFFF', 4), '00EE6D7FE55461600FFC58B9C873E7A61CED51D7FB9F015243527B04B3C0945B72E7AA9275D15B08FDED25EAA6761F2AA66AEFC767105D74496B2BFCD30A8BEED7', "check V of FFFF024100EE... at 4 with garbage");
  equal(ASN1HEX.getV('FFFF02818100D184617B5F8034655944839F785A63835555088A23D0B34E1A2E6BDF83C49BA2B1ECB398105EED1A21D513EA76F9AD3879843DB27E91765885BA33CCF45B1461C227205F08BCD07D5A2CF7FA9443CF2EF376F448503630699059002546D2F2EBA124478AC34704E3D83CD1E041178042A922FA3C541B3FDFEB072C5DC44A0021FFFF', 4), '00D184617B5F8034655944839F785A63835555088A23D0B34E1A2E6BDF83C49BA2B1ECB398105EED1A21D513EA76F9AD3879843DB27E91765885BA33CCF45B1461C227205F08BCD07D5A2CF7FA9443CF2EF376F448503630699059002546D2F2EBA124478AC34704E3D83CD1E041178042A922FA3C541B3FDFEB072C5DC44A0021', "check V of FFFF028181... at 4 with garbage");
});

test("ASN1HEX.getNextSiblingIdx", function() {
  expect(2);
  equal(ASN1HEX.getNextSiblingIdx('ff0201ab0201cdff', 2), 8, "next sibling of ff0201ab...");
  equal(ASN1HEX.getNextSiblingIdx('ff0202abab0201cdff', 2), 10, "next sibling of ff0202ab...");
});

test("ASN1HEX.getChildIdx seq", function() { 
  var h = "3018300f02010102010202010302010402010504027abc0401ff";
  var a = ASN1HEX.getChildIdx(h, 4);
  equal(a.length, 5, "check array size.");
  equal(ASN1HEX.getVblen(h, 4), 15, "check length.");
  equal(ASN1HEX.getNextSiblingIdx(h, 8), 14, "check 2nd sibling.");
  equal(a.join("/"), "8/14/20/26/32", "check array contents.");
});

test("ASN1HEX.getChildIdx int5", function() { 
  var a = ASN1HEX.getChildIdx("020105", 0);
  equal(a.join("/"), "4", "int 5>[4]");
});

test("ASN1HEX.getChildIdx bitstr0055", function() { 
  var a = ASN1HEX.getChildIdx("03020055", 0);
  equal(a.join("/"), "6", "bitstr 00555>[6]");
});

test("ASN1HEX.getNthChildIdx", function() { 
  var h = "300902012a02012b02012c";
  var h2 = "ff300902012a02012b02012c";
  expect(4);
  equal(ASN1HEX.getNthChildIdx(h, 0, 0), 4,  "nth = 1");
  equal(ASN1HEX.getNthChildIdx(h, 0, 1), 10, "nth = 2");
  equal(ASN1HEX.getNthChildIdx(h, 0, 2), 16, "nth = 3");
  equal(ASN1HEX.getNthChildIdx(h2, 0, 1), 12, "h2 nth = 2");
});

test("ASN1HEX.getIdxbyList", function() { 
  var h = "3016300902011a02011b02011c300902012a02012b02012c";
  equal(ASN1HEX.getChildIdx(h, 0).join("/"), "4/26", "array level 1");
  equal(ASN1HEX.getChildIdx(h, 4).join("/"), "8/14/20", "array level 2-1");
  equal(ASN1HEX.getChildIdx(h, 26).join("/"), "30/36/42", "array level 2-2");
  equal(ASN1HEX.getIdxbyList(h, 0, [0]), 4, "(0)=4");
  equal(ASN1HEX.getIdxbyList(h, 0, [1]), 26, "(1)=26");
  equal(ASN1HEX.getIdxbyList(h, 0, [0, 0]), 8, "(0,0)=8");
  equal(ASN1HEX.getIdxbyList(h, 0, [0, 1]), 14, "(0,1)=14");
  equal(ASN1HEX.getIdxbyList(h, 0, [0, 2]), 20, "(0,2)=20");
  equal(ASN1HEX.getIdxbyList(h, 0, [1, 0]), 30, "(1,0)=30");
  equal(ASN1HEX.getIdxbyList(h, 0, [1, 1]), 36, "(1,1)=36");
  equal(ASN1HEX.getIdxbyList(h, 0, [1, 2]), 42, "(1,2)=42");
  equal(ASN1HEX.getTLV(h, 36), "02012b", "02012b");
});

test("ASN1HEX.getIdxbyListEx same test as getIdxbyList", function() { 
  var h = "3016300902011a02011b02011c300902012a02012b02012c";
  equal(ASN1HEX.getChildIdx(h, 0).join("/"), "4/26", "array level 1");
  equal(ASN1HEX.getChildIdx(h, 4).join("/"), "8/14/20", "array level 2-1");
  equal(ASN1HEX.getChildIdx(h, 26).join("/"), "30/36/42", "array level 2-2");
  equal(ASN1HEX.getIdxbyListEx(h, 0, [0]), 4, "(0)=4");
  equal(ASN1HEX.getIdxbyListEx(h, 0, [1]), 26, "(1)=26");
  equal(ASN1HEX.getIdxbyListEx(h, 0, [0, 0]), 8, "(0,0)=8");
  equal(ASN1HEX.getIdxbyListEx(h, 0, [0, 1]), 14, "(0,1)=14");
  equal(ASN1HEX.getIdxbyListEx(h, 0, [0, 2]), 20, "(0,2)=20");
  equal(ASN1HEX.getIdxbyListEx(h, 0, [1, 0]), 30, "(1,0)=30");
  equal(ASN1HEX.getIdxbyListEx(h, 0, [1, 1]), 36, "(1,1)=36");
  equal(ASN1HEX.getIdxbyListEx(h, 0, [1, 2]), 42, "(1,2)=42");
  equal(ASN1HEX.getTLV(h, 36), "02012b", "02012b");
});

/*
3012 seq idx=0
  020101 int:1 idx=4
  020102 int:2 idx=10
  800103 [0]:3 idx=16
  810104 [1]:4 idx=22
  020105 int:5 idx=28
  020106 int:6 idx=34
 */
test("ASN1HEX.getIdxbyListEx context specific test1(skip count)", function() { 
var h = "3012020101020102800103810104020105020106";
equal(ASN1HEX.getIdxbyListEx(h, 0, [1]), 10, "[1]=10");
equal(ASN1HEX.getIdxbyListEx(h, 0, ["[0]"]), 16, "[[0]]=16"); // context tag
equal(ASN1HEX.getIdxbyListEx(h, 0, ["[1]"]), 22, "[[1]]=22"); // context tag
equal(ASN1HEX.getIdxbyListEx(h, 0, [2]), 28, "[2]=28"); // skip context tag
equal(ASN1HEX.getIdxbyListEx(h, 0, [3]), 34, "[3]=34"); // skip context tag
});

/*
3014 seq idx=0
  0412 octstr idx=4
    020101 int:1 idx=8
    020102 int:2 idx=14
    800103 [0]:3 idx=20
    810104 [1]:4 idx=26
    020105 int:5 idx=32
    020106 int:6 idx=38
 */
test("ASN1HEX.getIdxbyListEx context specific test2(dig into OctetString)", function() { 
var h = "30140412020101020102800103810104020105020106";
equal(ASN1HEX.getIdxbyListEx(h, 0, [0,1]), 14, "[0,1]=14");
equal(ASN1HEX.getIdxbyListEx(h, 0, [0,"[0]"]), 20, "[0,[0]]=20"); // context tag
equal(ASN1HEX.getIdxbyListEx(h, 0, [0,"[1]"]), 26, "[0,[1]]=26"); // context tag
equal(ASN1HEX.getIdxbyListEx(h, 0, [0,2]), 32, "[0,2]=32"); // skip context tag
equal(ASN1HEX.getIdxbyListEx(h, 0, [0,3]), 38, "[0,3]=38"); // skip context tag
});

/*
3015 seq idx=0
  031300 bitstr idx=4
    020101 int:1 idx=10
    020102 int:2 idx=16
    800103 [0]:3 idx=22
    810104 [1]:4 idx=28
    020105 int:5 idx=34
    020106 int:6 idx=40
 */
test("ASN1HEX.getIdxbyListEx context specific test3(dig into BitString)", function() { 
var h = "3015031300020101020102800103810104020105020106";
equal(ASN1HEX.getIdxbyListEx(h, 0, [0,1]), 16, "[0,1]=16");
equal(ASN1HEX.getIdxbyListEx(h, 0, [0,"[0]"]), 22, "[0,[0]]=22"); // context tag
equal(ASN1HEX.getIdxbyListEx(h, 0, [0,"[1]"]), 28, "[0,[1]]=28"); // context tag
equal(ASN1HEX.getIdxbyListEx(h, 0, [0,2]), 34, "[0,2]=34"); // skip context tag
equal(ASN1HEX.getIdxbyListEx(h, 0, [0,3]), 40, "[0,3]=40"); // skip context tag
});

test("ASN1HEX.getTLVbyList", function() { 
  var h = "3016300902011a02011b02011c300902012a02012b02012c";
  var h2 = "308201a830820152a0030201020209009e775e7d9f43abc9300d06092a864886f70d0101050500301a310b3009060355040613024a50310b3009060355040a13027a32301e170d3130303533313036313735365a170d3230303532383036313735365a301a310b3009060355040613024a50310b3009060355040a13027a32305c300d06092a864886f70d0101010500034b003048024100b9b00329505fe2ed60ec5689ddcdf5b94d05ab416e1643b1ca3f96fc472eeb1f62ed476897f159ae98b7f3adecec7971deb5f64d9a25901c4dc7a49772e5a02b0203010001a37b3079301d0603551d0e04160414bb30852881898321fd833aa39cc1808a09bdc68c304a0603551d23044330418014bb30852881898321fd833aa39cc1808a09bdc68ca11ea41c301a310b3009060355040613024a50310b3009060355040a13027a328209009e775e7d9f43abc9300c0603551d13040530030101ff300d06092a864886f70d01010505000341005859f3cabb652ed31c470f27ca2043eefc9f20270cdec5d45b0ba7b8c4f68337918425e8a632d29c1c87a59deb2a56f3aa5e978245384afe2e75463836a8c451";
  var h3 = "301a310b3009060355040613024a50310b3009060355040a13027a32";
  expect(3);
  equal(ASN1HEX.getTLVbyList(h, 0, [1, 1]), "02012b", "(1,1)=02012b");
  equal(ASN1HEX.getTLVbyList(h2, 0, [0, 3]), h3, "issuer");
  equal(ASN1HEX.getTLVbyList(h2, 0, [0, 5]), h3, "subject");
});

/*
3014 seq idx=0
  0412 octstr idx=4
    020101 int:1 idx=8
    020102 int:2 idx=14
    800103 [0]:3 idx=20
    810104 [1]:4 idx=26
    020105 int:5 idx=32
    020106 int:6 idx=38
 */
test("ASN1HEX.getTLVbyListEx", function() { 
var h = "30140412020101020102800103810104020105020106";
equal(ASN1HEX.getTLVbyListEx(h, 0, [0,1]), "020102", "[0,1]=020102");
equal(ASN1HEX.getTLVbyListEx(h, 0, [0,"[0]"]), "800103", "[0,[0]]=800103"); // context tag
equal(ASN1HEX.getTLVbyListEx(h, 0, [0,"[1]"]), "810104", "[0,[1]]=810104"); // context tag
equal(ASN1HEX.getTLVbyListEx(h, 0, [0,2]), "020105", "[0,2]=020105"); // skip context tag
equal(ASN1HEX.getTLVbyListEx(h, 0, [0,3]), "020106", "[0,3]=020106"); // skip context tag
})

test("getVbyList exception1 tag-unmatch", function() {
equal(ASN1HEX.getVbyList("3006020104020105", 0, [0, 0], "33"), 
  null,
  "null when tag unmatch");
});

test("getVbyList exception1 tag-unmatch2", function() {
equal(ASN1HEX.getVbyList("3006020104020105", 0, [300], "30"),
  null,
  "null when tag unmatch");
});

test("getVbyList int values", function() {
  equal(ASN1HEX.getVbyList("3006020104020105", 0, [0], "02"), "04", "4");
  equal(ASN1HEX.getVbyList("3006020104020105", 0, [1], "02"), "05", "5");
});

test("getVbyList DSA signature int values", function() {
  var s = "302c02146e41015afd8597894f42f466dde2190ebba6f15e0214787f9380a3a33011c88bf877df7ac3b8a62b854c";
  equal(ASN1HEX.getVbyList(s, 0, [0], "02"), "6e41015afd8597894f42f466dde2190ebba6f15e", "4");
  equal(ASN1HEX.getVbyList(s, 0, [1], "02"), "787f9380a3a33011c88bf877df7ac3b8a62b854c", "5");
});

/*
3015 seq idx=0
  3013 seq idx=4
    020101 int:1 idx=8
    020102 int:2 idx=14
    800103 [0]:3 idx=20
    810104 [1]:4 idx=26
    020105 int:5 idx=32
    03020006 int:6 idx=38
 */
test("ASN1HEX.getVbyListEx", function() { 
var h = "3015301302010102010280010381010402010503020006";
equal(ASN1HEX.getVbyListEx(h, 0, [0,1]), "02", "[0,1]=02");
equal(ASN1HEX.getVbyListEx(h, 0, [0,"[0]"]), "03", "[0,[0]]=03"); // context tag
equal(ASN1HEX.getVbyListEx(h, 0, [0,"[1]"]), "04", "[0,[1]]=04"); // context tag
equal(ASN1HEX.getVbyListEx(h, 0, [0,2]), "05", "[0,2]=05"); // skip context tag
equal(ASN1HEX.getVbyListEx(h, 0, [0,3]), "06", "[0,3]=06"); // skip context tag
equal(ASN1HEX.getVbyListEx(h, 0, [0,3], "03", false), "0006", "[0,3]=0006"); // don't remove unusedbits
})

test("ASN1HEX.getInt test", function() {
var _getInt = ASN1HEX.getInt;
equal(_getInt("xxxx020103xxxxxx", 4), 3, "int 3");
equal(_getInt("xxxx03020780xxxxxx", 4), 1, "bitstr 0780 = 1");
equal(_getInt("xxxx030203c8xxxxxx", 4), 25, "bitstr 03c8 = 25");
});

/*
test("oidstrtohex", function() {
  expect(3);
  equal(ASN1HEX.oidstrtohex("1.2"), "2a", "1.2>2a");
  equal(ASN1HEX.oidstrtohex("2.16.840.1.101.3.4.2.1"),
        "608648016503040201", "sha256");
  equal(ASN1HEX.oidstrtohex("1.2.840.113549.1.1.5"),
        "2a864886f70d010105", "SHA1withRSA");
});
 */

test("hextooidstr", function() {
  equal(ASN1HEX.hextooidstr("2a"), "1.2", "2a->1.2");
  equal(ASN1HEX.hextooidstr("608648016503040201"),  // SHA256
        "2.16.840.1.101.3.4.2.1", "sha256");
  equal(ASN1HEX.hextooidstr("2a864886f70d010105"),
        "1.2.840.113549.1.1.5", "SHA1withRSA");
});

/*
{"seq": [
  {"octstr": {"obj": {"seq": [{"int": 3},{"int":4}]}}},
  {"bitstr": {"obj": {"seq": [{"int": 5},{"int":6}]}}},
  {"prnstr": "aaa"}
  ]} 
 */

test("getDecendantIndexByNthList", function() {
//                                 ^bit  ^seq^int  ^int  ^prn^aaa             
//             ^oct^seq^int  ^int                                    
  var h = "301a0408300602010302010403090030060201050201061303616161";
  equal(ASN1HEX.getIdxbyList(h, 0, [0]), 4, "octstr") 
  equal(ASN1HEX.getIdxbyList(h, 0, [1]), 24, "bitstr") 
  equal(ASN1HEX.getIdxbyList(h, 0, [2]), 46, "prnstr") 

  equal(ASN1HEX.getIdxbyList(h, 0, [0, 0]), 8, "octstr seq") 
  equal(ASN1HEX.getIdxbyList(h, 0, [0, 0, 0]), 12, "octstr seq int3") 
  equal(ASN1HEX.getIdxbyList(h, 0, [0, 0, 1]), 18, "octstr seq int4") 

  equal(ASN1HEX.getIdxbyList(h, 0, [1, 0]), 30, "binstr seq") 
  equal(ASN1HEX.getIdxbyList(h, 0, [1, 0, 0]), 34, "bitstr seq int5") 
  equal(ASN1HEX.getIdxbyList(h, 0, [1, 0, 1]), 40, "bitstr seq int6") 
});

/*
h = 
SEQUENCE
  SEQUENCE
    INTEGER 1a
    INTEGER 1b
    INTEGER 1c
  SEQUENCE
    INTEGER 2a
    INTEGER 2b
    INTEGER 2c
 */
test("getIdxbyList", function() { 
  var h = "3016300902011a02011b02011c300902012a02012b02012c";
  equal(ASN1HEX.getChildIdx(h, 0).join("/"), "4/26", "array level 1");
  equal(ASN1HEX.getChildIdx(h, 4).join("/"), "8/14/20", "array level 2-1");
  equal(ASN1HEX.getChildIdx(h, 26).join("/"), "30/36/42", "array level 2-2");
  equal(ASN1HEX.getIdxbyList(h, 0, [0]), 4, "(0)=4");
  equal(ASN1HEX.getIdxbyList(h, 0, [0], "30"), 4, "(0)=4 with checkTag");
  equal(ASN1HEX.getIdxbyList(h, 0, [1]), 26, "(1)=26");
  equal(ASN1HEX.getIdxbyList(h, 0, [0, 0]), 8, "(0,0)=8");
  equal(ASN1HEX.getIdxbyList(h, 0, [0, 1]), 14, "(0,1)=14");
  equal(ASN1HEX.getIdxbyList(h, 0, [0, 2]), 20, "(0,2)=20");
  equal(ASN1HEX.getIdxbyList(h, 0, [1, 0]), 30, "(1,0)=30");
  equal(ASN1HEX.getIdxbyList(h, 0, [1, 1]), 36, "(1,1)=36");
  equal(ASN1HEX.getIdxbyList(h, 0, [1, 2]), 42, "(1,2)=42");
  equal(ASN1HEX.getIdxbyList(h, 0, [1, 5]), -1, "no [1,5]");
  equal(ASN1HEX.getTLV(h, 36), "02012b", "02012b");
  equal(ASN1HEX.getIdxbyList(h, 0, [0], "31"), -1, "(0)=4 with checkTag=31 shall fail");
});

test("oidname", function() {
  equal(ASN1HEX.oidname("2.5.29.37"), "extKeyUsage", "2.5.29.37 > extKeyUsage");
  equal(ASN1HEX.oidname("551d25"), "extKeyUsage", "551d25 > extKeyUsage");
  equal(ASN1HEX.oidname("0.1.2.3"), "0.1.2.3", "0.1.2.3 > 0.1.2.3");
});

test("ASN1HEX.isASN1HEX test", function() {
equal(ASN1HEX.isASN1HEX("030101"), true, "030101 > true");
equal(ASN1HEX.isASN1HEX("3003020101"), true, "3003020101 > true");
equal(ASN1HEX.isASN1HEX("010203"), false, "010203 > false");
equal(ASN1HEX.isASN1HEX(sZ4_CERPEM), false, "sZ4_CERPEM > false");
});

test("isContextTag without sTag test", function() {
equal(ASN1HEX.isContextTag("a0"), true, "a0=true");
equal(ASN1HEX.isContextTag("80"), true, "80=true");
equal(ASN1HEX.isContextTag("30"), false, "30=false");
equal(ASN1HEX.isContextTag("06"), false, "06=false");
});

test("isContextTag with sTag test", function() {
equal(ASN1HEX.isContextTag("a0", "[0]"), true, "a0=[0] true");
equal(ASN1HEX.isContextTag("a1", "[1]"), true, "a1=[1] true");
equal(ASN1HEX.isContextTag("bf", "[31]"), true, "bf=[31] true");
equal(ASN1HEX.isContextTag("80", "[0]"), true, "80=[0] true");
equal(ASN1HEX.isContextTag("81", "[1]"), true, "81=[1] true");
equal(ASN1HEX.isContextTag("81", "abcd"), false, "81=abcd false");
equal(ASN1HEX.isContextTag("a0", "[3]"), false, "a0=[3] false");
});

});

</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<p>
<a href="../">TOP</a> | 
<a href="index.html">TEST INDEX</a> | 
</p>
</body>
</html>
